package cn.xny.user.controller;

import cn.xny.basic.exception.BusinessException;
import cn.xny.user.dto.LoginDto;
import cn.xny.user.service.LogininfoService;
import cn.xny.user.domain.Logininfo;
import cn.xny.user.query.LogininfoQuery;
import cn.xny.basic.util.AjaxResult;
import cn.xny.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

/**
 * 后端接口类；
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    public LogininfoService logininfoService;

   @PostMapping("/account")
    public AjaxResult accountLogin(@RequestBody LoginDto loginDto){
       try {
         Map<String,Object> map =logininfoService.accountLogin(loginDto);


           return AjaxResult.me().setObj(map);

       } catch (BusinessException e) {
           e.printStackTrace();
           return new  AjaxResult(false,e.getMessage());
       }catch (Exception e) {
           e.printStackTrace();
           return new  AjaxResult(false,"系统错误，请重试");
       }

   }
   //微信扫码登录
    @PostMapping("/wechat")
    public AjaxResult wechatLogin(@RequestBody Map<String,String> map){
        try {
              return logininfoService.wechatLogin(map);




        } catch (BusinessException e) {
            e.printStackTrace();
            return new  AjaxResult(false,e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return new  AjaxResult(false,"系统错误，请重试");
        }

    }
    /**
     * 微信绑定
     * @param map
     * @return
     */
    @PostMapping("/wechat/binder")
    public AjaxResult wechatBinder(@RequestBody Map<String,String> map){
        try {
            return logininfoService.wechatBinder(map);
        } catch (BusinessException e) {
            return new AjaxResult(false,e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"系统繁忙，请稍后重试!!!");
        }
    }
}

